package com.example.demo.controller;

import com.example.demo.entity.User;
import com.example.demo.mapper.UserMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.List;

/**
 * @program:demo
 * @description: User控制层
 * @author: 王子健
 * @create: 2019-12-25
 */
@Api(tags = "user")
@RestController
@EnableSwagger2
public class UserController {
    @Autowired
    private UserMapper userMapper;

    /*添加用户*/
    @ApiOperation(value = "用户添加")
    @GetMapping("/addUser")
    public int AddUser(User user){
        if (user!=null){
            if (user.getId()!=0){
                //是否可以添加此主键
            }
        }
        return userMapper.insertUser(user);
    }

    /*删除用户*/
    @ApiOperation("删除用户")
    @GetMapping("/deleteUser")
    public int deleteUser(int id){
        return userMapper.deleteUser(id);
    }

    /*更新用户信息*/
    @ApiOperation("更新用户信息")
    @PostMapping("/updateUser")
    public int updateUser(User user) {
        return userMapper.updateUser(user);
    }

    /*查询所有用户*/
    @ApiOperation("查询用户")
    @GetMapping("/selectAllUsers")
    public List<User> selectAllUsers() {
        return userMapper.selectAllUsers();
    }
}
